package red.service.impl;

import red.dao.UserDao;
import red.dao.impl.UserDaoImpl;
import red.model.ResModel;
import red.model.UserModel;
import red.service.LoginService;
import red.util.Model;

import java.util.List;


public class LoginServiceImpl implements LoginService {
    private UserDao userDao=new UserDaoImpl();
    @Override
    public ResModel loginuser(Model model) {
        UserModel param =new UserModel();
        param.setPassword(model.getString("password"));
        param.setUser_name(model.getString("user_name"));
        List<UserModel> list = userDao.loginUser(param);
        ResModel resModel;
        if (list.size()<1)
        {
            resModel = new ResModel();
            resModel.setMsg("用户不存在");
            resModel.setRes(false);
            return resModel;
        }
        for (int i=0;i<list.size();i++){
            String uerrname;
            String password;
            UserModel userModel=list.get(i);
            uerrname= userModel.getUser_name();
            password=userModel.getPassword();
            if (param.getUser_name().equals(uerrname) && param.getPassword().equals(password))
            {
                resModel = new ResModel();
                resModel.setMsg("登录成功");
                resModel.setRes(true);
                return resModel;
            }
        }
        resModel = new ResModel();
        resModel.setMsg("登录失败，用户名或密码错误");
        resModel.setRes(false);
        return resModel;
    }
}
